package org.meandslava.calc.utils;

import java.text.DecimalFormat;

import android.text.Editable;

public class FixedNumber extends Term {
	//private double number;
	private boolean hasPoint = false;
	private int afterDigit = 0;
	private StringBuilder builder = new StringBuilder();
	
	public FixedNumber(int number){
		builder.append(number);
	}
	public FixedNumber(double number){
		builder.append(format.format(number));
		if(builder.toString().contains(".")){
			hasPoint = true;
		}
		//this.number = number;
		/*if(number - Math.floor(number) > Double.MIN_VALUE){
			hasPoint = true;
		}*/
	}
	
	@Override
	public double getResult() {
		//return number;
		return Double.parseDouble(builder.toString());
	}

	@Override
	public void applyDigit(int digit) {
		/*number*=Math.pow(10, afterDigit);
		number+=digit;*/
		builder.append(digit);
	}

	@Override
	public void applyPoint() {
		if(!hasPoint){
			hasPoint = true;
			builder.append('.');
		}
	}
	
	@Override
	public void writeExpression(Editable editable) {
		editable.append(builder.toString());
	}
	
	@Override
	public boolean back() {
		if(builder.length() == 0){
			return true;
		}else{
			if(builder.deleteCharAt(builder.length()-1).length() == 0){
				return true;
			}
		}
		return false;
	}

}
